<?php

namespace App\Admin\Grid\Displayers;

class ProgressBar extends AbstractDisplayer
{
    /**
     * @param string $style 颜色
     * @param int    $maxValue 进度条最大值
     * @param int    $precision 显示的进度值精确的小数点位数,最大为2
     * @return string
     */
    public function display($maxValue = 100, $style = 'green', $precision = 0)
    {
        $precision = $precision > 2 ? 2 : $precision;

        $value = round(((float)$this->value / $maxValue * 100), $precision);
        $value = sprintf("%.{$precision}f", $value);

        return <<<EOT

<div class="layui-progress" lay-showPercent="true">
  <div class="layui-progress-bar layui-bg-{$style}" lay-percent="{$value}%"></div>
</div>

EOT;
    }
}
